<?php
include_once('config.php');
include_once(mnminclude.'KMessaging.php');
	
if($_POST['xmlhttp']){
	if ($_POST['email'] == '') {
		echo 'noemail';
		die();
	}
	else {
		if (!check_email_address($_POST['email'])) {
			echo 'noemail';
			die();
		}
	}
	if ($_POST['body'] == '') {
		echo 'nobody';
		die();
	}

	$message =  new KMessaging();
	$message->tblName = table_messages;
	$body = '有人向您发出了档案认领请求，待认领档案为<a href="user.php?uid=' .$_POST['profile'] . '" target="_blank">' . $_POST['profilename'] . '</a>.  认领信息如下：<br>';
	$uniq = rand();
	$body .= $_POST['body'];
	$body = $body . "<br><br>" . '您可使用其提供的电子邮件('. $_POST['email'] .')与其进一步联系，也可直接<a href="javascript:" onclick="accept_prof_req('. $_POST['profile'] . ',' . $uniq .')">接受</a>或<a href="javascript:" onclick="deny_prof_req('. $_POST['profile'] . ',' . $uniq .')">拒绝</a>此认领请求.' . '<input type="hidden" id="'. $uniq .'" value="'. $_POST['email'] . '" />';
	
	$sendmsg = $message->SendMessege($_POST['title'],$body,$_POST['sender'],$_POST['receiver'],$_POST['senderlevel']);
	//echo $sendmsg . " end sql";
	//die();
	switch ($sendmsg) {
		case 0:
			echo "success";
			die();
			break;
		case 2:
			echo "nobody";
			die();
			break;
		case 1:
			echo "notitle";
			die();
			break;
		case 6:
			echo "database_error";
			die();
			break;
		default:
			echo "fail";
			die();
			break;
	}
}
?>